#! /bin/sh -vx
# $Id$
# Copyright 2017 Karl Berry <tex-live@tug.org>
# Copyright 2011-2015 Peter Breitenlohner <tex-live@tug.org>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_ttfdump=$BinDir/ttfdump$ExeExt

# pre-generated test results in the repository are stored in LF
# but the output might be written in CRLF on some platform.
# if 'diff --strip-trailing-cr' is available, exploit it.
# (useful for tests on win32 binaries run on MSYS shell)
DIFF="diff"
$DIFF --strip-trailing-cr $0 $0 \
  && DIFF="diff --strip-trailing-cr" || echo

TEXMFCNF=$srcdir/../kpathsea
TTFONTS=$srcdir/tests
export TEXMFCNF TTFONTS

failed=

rm -rf ttftest.*
#rm -rf FonetikaDaniaIwonaeRegular.ttf bad.otf test.ttc texmfhome.otf ttftest.*
#cp $srcdir/tests/FonetikaDaniaIwonaeRegular.ttf .
#cp $srcdir/tests/bad.otf .
#cp $srcdir/tests/test.ttc .
#cp $srcdir/tests/texmfhome.otf .

echo "*** ttfdump -t glyf -g 1 -o ttftest.glyf FonetikaDaniaIwonaeRegular.ttf" \
        && $_ttfdump -t glyf -g 1 -o ttftest.glyf FonetikaDaniaIwonaeRegular.ttf \
	&& diff -b $srcdir/tests/ttfdump.glyf ttftest.glyf \
	&& echo "ttfdump.glyf tests OK" && echo \
	|| failed="$failed ttfdump.glyf"

echo "*** ttfdump -t GPOS -o ttftest.gpos FonetikaDaniaIwonaeRegular.ttf" \
        && $_ttfdump -t GPOS -o ttftest.gpos FonetikaDaniaIwonaeRegular.ttf \
	&& diff -b $srcdir/tests/ttfdump.gpos ttftest.gpos \
	&& echo "ttfdump.gpos tests OK" && echo \
	|| failed="$failed ttfdump.gpos"

echo "*** ttfdump -t GSUB -o ttftest.gsub FonetikaDaniaIwonaeRegular.ttf" \
        && $_ttfdump -t GSUB -o ttftest.gsub FonetikaDaniaIwonaeRegular.ttf \
	&& diff -b $srcdir/tests/ttfdump.gsub ttftest.gsub \
	&& echo "ttfdump.gsub tests OK" && echo \
	|| failed="$failed ttfdump.gsub"

echo "*** ttfdump -t head FonetikaDaniaIwonaeRegular.ttf >ttftest.head" \
        && $_ttfdump -t head FonetikaDaniaIwonaeRegular.ttf >ttftest.head \
	&& $DIFF -b $srcdir/tests/ttfdump.head ttftest.head \
	&& echo "ttfdump.head tests OK" && echo \
	|| failed="$failed ttfdump.head"

echo "*** ttfdump -t OS/2 texmfhome.otf >ttftest.os_2" \
        && $_ttfdump -t OS/2 texmfhome.otf >ttftest.os_2 \
	&& $DIFF -b $srcdir/tests/ttfdump.os_2 ttftest.os_2 \
	&& echo "ttfdump.os_2 tests OK" && echo \
	|| failed="$failed ttfdump.os_2"

echo "*** ttfdump -t OS/2 bad.otf >ttftest.bad" \
        && $_ttfdump -t OS/2 bad.otf >ttftest.bad \
	&& $DIFF -b $srcdir/tests/ttfdump.bad ttftest.bad \
	&& echo "ttfdump.bad tests OK" && echo \
	|| failed="$failed ttfdump.bad"

echo "*** ttfdump -t gasp -c 0 test.ttc >ttftest.gasp" \
	&& $_ttfdump -t gasp -c 0 test.ttc >ttftest.gasp \
	&& $DIFF -b $srcdir/tests/ttfdump.gasp ttftest.gasp \
	&& echo "ttfdump.gasp tests OK" && echo \
	|| failed="$failed ttfdump.gasp"

echo "*** ttfdump -t maxp -c 1 test.ttc >ttftest.maxp" \
	&& $_ttfdump -t maxp -c 1 test.ttc >ttftest.maxp \
	&& $DIFF -b $srcdir/tests/ttfdump.maxp ttftest.maxp \
	&& echo "ttfdump.maxp tests OK" && echo \
	|| failed="$failed ttfdump.maxp"

test -z "$failed" && exit 0
echo "failed tests:$failed"
exit 1

